package com.gitee.cirnochat.chat.model.vo.req;

import com.gitee.cirnochat.chat.model.enums.ChatSessionType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

@Data
@Schema(description = "撤回消息请求")
public class ChatMessageRevokeRequest {
    @Schema(description = "消息ID", example = "1234567890")
    @NotBlank(message = "消息ID不能为空")
    private Long messageId;

    @Schema(description = "会话ID;当会话类型为\"group\"时，会去检验群聊是否存在", example = "1234567890")
    @NotBlank(message = "会话ID不能为空")
    private Long sessionId;

    @Schema(description = "会话类型", example = "private")
    @NotNull(message = "会话类型不能为空")
    private ChatSessionType sessionType;

    @Schema(description = "撤回时间戳，单位为毫秒", example = "1633036800000")
    @NotNull(message = "撤回时间戳不能为空")
    private Long createTime; // 创建时间，单位为毫秒

    /**
     * 检查撤回请求是否有效
     * 撤回请求在创建后2分钟内有效
     * @return true 如果撤回请求有效，false 如果无效
     */
    @Schema(hidden = true)
    @AssertTrue(message = "撤回请求已过期，必须在2分钟内进行撤回")
    public boolean isValidRevoke() {
        if (createTime == null) {
            return false;
        }
        long now = System.currentTimeMillis();
        // 2分钟 = 120000毫秒
        return now - createTime <= 120_000;
    }
}
